package com.huiyan.hysys.util;

import java.lang.reflect.Field;

public class BeanUtil {

    /**
     * 快速实现对象的复制
     * @param clz
     * @param obj
     * @param <T>
     * @return
     */
    public static <T> T copyBean(Class<T> clz,Object obj){
        T t = null;
        try{
            t = clz.newInstance();
            Field[] fields = obj.getClass().getDeclaredFields();
            for (Field f : fields) {
                f.setAccessible(true);
                Field field = clz.getDeclaredField(f.getName());
                if (field != null){
                    field.setAccessible(true);
                    field.set(t,f.get(obj));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return t;
    }


}
